package com.mapull.list;

import com.mapull.compare.Animal;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * @author mapull
 */
public class ListMaxMin {

    public static void main(String[] args) {
        List<Integer> list = Arrays.asList(1,4,2,8,7,5,3);
        findMaxAnimal();
    }

    private static void findMax(List<Integer> list){
        int max = list.stream().mapToInt(i -> i).max().orElse(0);
        System.out.println(max);
    }

    private static void findMin(List<Integer> list){
        int min = list.stream().mapToInt(i -> i).min().orElse(0);
        System.out.println(min);
    }

    private static void findMaxAnimal(){
        Animal dog = new Animal();
        dog.setName("狗");
        dog.setWeight(10);

        Animal chicken = new Animal();
        chicken.setName("鸡");
        chicken.setWeight(2);

        Animal pig = new Animal();
        pig.setName("猪");
        pig.setWeight(60);

        List<Animal> animals = new ArrayList<>();
        animals.add(dog);
        animals.add(chicken);
        animals.add(pig);

        Animal animal = animals.stream()
                .max(Comparator.comparing(Animal::getWeight))
                .orElse(null);
        System.out.println(animal);
    }
}
